from flask import Flask,jsonify,request
import json
from flask.config import Config
from werkzeug import datastructures
app = Flask(__name__)
from db import db1
from config import Config
from flask_cors import CORS
app.config.from_object(Config)
CORS(app)

@app.route('/test',methods=['POST','GET'])
def test():
    if request.method=='POST':
        data =request.data
        if data:
            data = json.loads(data)
        else:
            data = request.form
        sql = "insert into test values(0,'%s','%s')"%(data['name'],data['type'])
        db1.update(sql)
        return jsonify({'code':200})

    elif request.method=='GET':
        sql = "select * from test"
        res = db1.findall(sql)
        return jsonify({'code':200,'list':res})

if __name__ == '__main__':
    app.run()
    